//
//  MyView.m
//  ClassifyShop
//
//  Created by yuyao on 15/2/26.
//  Copyright (c) 2015年 yuyao. All rights reserved.
//

#import "MyView.h"
#import "Masonry.h"
@implementation MyView
@synthesize isUp,removeButton,removeDelegate,viewId,isLean;
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(size);
    // 绘制改变大小的图片
    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
    // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    // 返回新的改变大小后的图片
    return scaledImage;
}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(10,0,27,27)];
        [iamgeView setImage:[UIImage imageNamed:@"删除.png"]];

        if(self.tag!=100){
            removeButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [removeButton setFrame:CGRectMake(self.frame.size.width-35,-5, 40, 40)];
            [removeButton addSubview:iamgeView];
            [removeButton addTarget:self action:@selector(removeView:) forControlEvents:UIControlEventTouchUpInside];
            [removeButton setHidden:YES];
            [self addSubview:removeButton];

        }

        
    }
    return self;
}
- (void)removeView:(id)sender{
    
    [removeDelegate removedToReloadViews:(int)(self.viewId)];

}
- (void)showRemoveButton:(BOOL)boo{
    if(self.tag!=100){
        [removeButton setHidden:!boo];
    }
    if (boo) {
        
        [self bringSubviewToFront:removeButton];
        
    }
}
- (void)setLean:(BOOL)boo{
    self.isLean = boo;
    if (boo) {
       self.layer.transform = CATransform3DMakeRotation(-M_PI/8, 1, 0, 0);
    }else{
        self.layer.transform = CATransform3DMakeRotation(0, 1, 0, 0);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
